#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 1e5 + 10;

int n , m;
int a[N];


int check(int x)
{
    int sum = 0, cnt = 0;
    for(int i = 1;i <= n;i ++)
    {
        sum += a[i];
        if(sum > x)
        {
            cnt++;
            sum = a[i];
        }
    }
    return cnt + 1;
}
signed main()
{
    cin >> n >> m;
    int l = 0 , r = 0;
    for(int i = 1;i <= n;i ++)
    {
        cin >> a[i];
        l = max(l , a[i]);
        r += a[i];
    }
    while(l < r)
    {
        int mid = l + r >> 1;
        if(check(mid) <= m) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
    return 0;
}